T = int(input())
for _ in range(T):
    k = list(map(int, input().split()))
    k1 = k[0]
    less = sum(1 for x in k if x < k1)
    equal = sum(1 for x in k if x == k1)
    needed = max(0, 5 - (less + equal))
    print(needed)